#include "Comm.hpp"
int main()
{
    Fifo fifo(PATH);
    int fd = open(PATH, O_RDONLY);
    if (fd == -1)
    {
        cerr << "open fail, errno is " << errno << "errstring is " << strerror(errno) << endl;
        exit(0);
    }
    //fifo特点：如果写端没有打开，读端先打开，那么会在open时阻塞，直到写端被打开，open才会返回
    cout << "open success! " << endl;
    char buffer[1024];
    while (true)
    {
        int n = read(fd, &buffer, sizeof(buffer) - 1);
        if (n > 0)
        {
            buffer[n] = '\0';
            cout << "client say:" << buffer << endl;
        }
        else if (n == 0)
        {
            cout << "client exit" << endl;
            break;
        }
        else
        {
            cerr << "read fail, errno is " << errno << "errstring is " << strerror(errno) << endl;
            break;
        }
    }
    close(fd);
    return 0;
}
